var gl_vue_vm_list_inventory_html = $('#vue_vm_list_inventory').html();

$(function() {
	$('#vue_vm_list').hide();
    $('#vue_vm_list_inventory').hide();
});

function openTotalPage_history() {
	var pageParam = {};
	pageParam.type = 'timeInterval';
	pageParam.beHospitalId = $('input:radio[name="elderId"]:checked').attr('beHospitalId');
	pageParam.startTime = $('input:radio[name="elderId"]:checked').attr('startTime');
	pageParam.endTime = $('input:radio[name="elderId"]:checked').attr('endTime');
	
	if(!pageParam.beHospitalId) {
		alert('请查询并选择一位长者');
		return;
	}
	
	window.open('6-2-10paylist-total.html?pageParam='+encodeURIComponent(JSON.stringify(pageParam)));
}

function find_elder_history() {
	if($('#vue_vm_list').length==0) {return;}
	$('#vue_vm_list').hide();
	$('#inputSection').show();
	
	var searchVal = $('#searchVal').val();
	if(isEmpty(searchVal)) {
		searchVal = $.url().param('searchVal');
	}
	
	find_basic_by_json(path+'/elderBeHospital/findHistory', {searchVal: searchVal}, function(response) {
		$('#vue_vm_list').html(gl_vue_vm_list_html);
		
		new Vue({
			el: '#vue_vm_list',
			data: {
				todos: response.data
			},
			methods: {
				getChepingUrl:function(elderId, elderName, elderCardId) {
					return getChepingUrl(elderId, elderName, elderCardId);
				},
				onFindElderChange:function(elderCardId) {
					if(findElder) {
						findElder(elderCardId);
					}
				},
				onFindElderByElderIDChange:function(elderId) {
					if(findElderInfoByElderId) {
						findElderInfoByElderId(elderId);
					}
				},
				onRadioClick:function() {
					var beHospitalId = $('input:radio[name="elderId"]:checked').attr('beHospitalId');
					var elderCardId = $('input:radio[name="elderId"]:checked').attr('cardId');
                    find_costInventory_by_history(beHospitalId);
					// if(autoSearchDetail) {
					// 	autoSearchDetail(elderCardId);
					// }
					// if(elderArrearage_find) {
					// 	elderArrearage_find(elderCardId);
					// }
				},
				onRadioClickElderType:function(elderType) {
					if(!elderType || elderType!=1) {
						$('#inputSection').hide();
						alert('院外长者不能办理入院登记');
						return;
					}else {
						$('#inputSection').show();
					}
				}
			}
		});
		$('#vue_vm_list').show();
	});
}

function find_costInventory_by_history(beHospitalId) {

    find_basic_by_json(path+'/elderPayRecord/findByBeHospitalId', {beHospitalId: beHospitalId}, function(response) {

        $('#vue_vm_list_inventory').html(gl_vue_vm_list_inventory_html);
        new Vue({
            el: '#vue_vm_list_inventory',
            data: {
                todos: response.data
            },
            methods: {
                getTitle:function() {
                },
                openTotalPage:function() {
                },
                openPrintPage:function(paperType) {
                },
                getElderPayRecordTotalMoney:function(forms) {
                    var totalMoney = 0;
                    if(forms) {
                        for(var i=0; i<forms.length; i++) {
                        	if(forms[i].payWay==3){//如果是vip卡扣费
								continue;
							}
                            totalMoney += forms[i].payMoney;
                        }
                    }

                    return totalMoney;
                },
                getElderArrearageTotalMoney:function(forms) {
                    var totalMoney = 0;
                    if(forms) {
                        for(var i=0; i<forms.length; i++) {
                            totalMoney += forms[i].arrearageMoney;
                        }
                    }
                    return totalMoney;
                }
            }
        });

        $('#vue_vm_list_inventory').show();
    });
}